#include <windows.h>
#include "Lock.h"

CMutex::CMutex()
{
	m_hLock = CreateMutex(NULL, FALSE, NULL);
}

CMutex::~CMutex()
{
	Release();
	CloseHandle(m_hLock);
}

void CMutex::Apply()
{
	WaitForSingleObject(m_hLock, INFINITE);
}

void CMutex::Release()
{
	ReleaseMutex(m_hLock);
}


CSemaphore::CSemaphore(int SemaphoreCnt)
{
	m_hLock = CreateSemaphore(NULL, SemaphoreCnt, SemaphoreCnt, NULL);
}

CSemaphore::~CSemaphore()
{
	Release();
	CloseHandle(m_hLock);
}

void CSemaphore::Apply()
{
	WaitForSingleObject(m_hLock, INFINITE);
}

void CSemaphore::Release()
{
	ReleaseSemaphore(m_hLock, 1, NULL);
}
